classdef spyfilt_poly_lbl < spyview_filter
    properties (Constant=true)
        name='Poly-LBL';
        description='Subtract a polynomial from each line';
        parameters=struct('name',{'Order','Vertical'},'type',{'float','bool'},'default',{2,0},'min',{0,0},'max',{4,0});
    end
    methods
        function [pm,px,py]=filter(sf,pm,px,py)            
            if sf.values{2}
               for i=1:size(pm,2)
                   p=polyfit(py(:),pm(:,i),ceil(sf.values{1}));
                   pm(:,i)=pm(:,i)-polyval(p,py(:));
               end
            else
               for i=1:size(pm,1)
                   p=polyfit(px(:)',pm(i,:),ceil(sf.values{1}));
                   pm(i,:)=pm(i,:)-polyval(p,px(:)');
               end
            end
        end
    end
end